<?php
require_once('./class/Evenement.php');
require_once('./class/Association.php');
require_once('./class/Lieu.php');
require_once('./class/Statistique.php');
require_once('./class/CommentEvenement.php');
require_once('./class/Frequence.php');

switch(@$_GET['action']){

    default:
        echo _EVENEMENT_;
    break;

    case "addForm":
        echo Evenement::getAddForm();
        break;

    case "doAdd":
        $e = new Evenement();
        $e->setIdEvenement(null);
        $e->setIdAssociation($_POST['id_association']);
        $e->setIdFrequence($_POST['id_frequence']);
        $e->setIdLieu($_POST['id_lieu']);
        $e->setNom($_POST['nom']);
        $e->setCout($_POST['cout']);
        $e->setDateCreation($_POST['date_creation']);
        $e->setDateDebut($_POST['date_debut']);
        $e->setDateFin($_POST['date_fin']);
        $e->setDescription($_POST['description']);
        $e->setNombrePlace($_POST['nombre_place']);
        $e->setTarifExte($_POST['tarif_exte']);
        $e->setTarifAdherent($_POST['tarif_adherent']);
        $e->addOrModify();
        echo $e->getNom()." "._ADDED_;
        break;

    case "modifyForm":
        $e = Evenement::getEvenement($_GET['id']);
        echo $e->getModifyForm();
        break;

    case "doModify":
        $e = new Evenement();
        $e->setIdEvenement($_POST['id_evenement']);
        $e->setIdAssociation($_POST['id_association']);
        $e->setIdFrequence($_POST['id_frequence']);
        $e->setIdLieu($_POST['id_lieu']);
        $e->setNom($_POST['nom']);
        $e->setCout($_POST['cout']);
        $e->setDateCreation($_POST['date_creation']);
        $e->setDateDebut($_POST['date_debut']);
        $e->setDateFin($_POST['date_fin']);
        $e->setDescription($_POST['description']);
        $e->setNombrePlace($_POST['nombre_place']);
        $e->setTarifExte($_POST['tarif_exte']);
        $e->setTarifAdherent($_POST['tarif_adherent']);
        $e->addOrModify();
        echo _EVENEMENT_.' '._MODIFIED_;
        break;

    case "list":
        $evenement_array = Evenement::getAllEvenement();
        $html = '<table class="tablesorter">
						<thead>
							<th>'._ID_EVENEMENT_.'</th>
							<th>'._NOM_EVENEMENT_.'</th>
							<th>'._ASSOCIATION_.'</th>
							<th>'._LIEU_.'</th>
							<th>'._FREQUENCE_.'</th>
							<th>'._DATE_CREATION_.'</th>
							<th>'._COUT_EVENEMENT_.'</th>
							<th>'._TARIF_EXTERIEUR_.'</th>
							<th>'._TARIF_ADHERENT_.'</th>
							<th>'._DESCRIPTION_.'</th>
							<th>'._DATE_DEBUT_.'</th>
							<th>'._DATE_FIN_.'</th>
							<th>'._NOMBRE_PLACE_.'</th>
							<th>'._NOTE_MOYENNE_.'</th>
							<th>'._LIST_PARTICIPANT_.'</th>
							<th>'._NOTE_.'</th>							
							<th>'._COMMENTAIRE_.'</th>
							<th>'._EQUIPE_.'</th>
							<th>'._EDIT_.'</th>
							<th>'._DELETE_.'</th>
							
						</thead>
						<tbody>';
        $i = 0;
        foreach($evenement_array as $e){
            $a = Association::getAssociation($e->getIdAssociation());
            $l = Lieu::getLieu($e->getIdLieu());
            $n= Statistique::getAverageNoteForEvenement($e->getIdEvenement());
            $f = Frequence::getFrequence($e->getIdFrequence());
            $odd = ($i % 2 == 0) ? 'class="odd"' : "";
            $i++;
            $html .= '<tr '.$odd.'>
						<td>'.$e->getIdEvenement().'</td>
						<td>'.$e->getNom().'</td>
						<td>'.$a->getNom().'</td>
						<td>'.$l->getNom().'</td>
						<td>'.$f->getNom().'</td>
						<td>'.$e->getDateCreation().'</td>
						<td>'.$e->getCout().'</td>
						<td>'.$e->getTarifExte().'</td>
						<td>'.$e->getTarifAdherent().'</td>
						<td>'.$e->getDescription().'</td>
						<td>'.$e->getDateDebut().'</td>
						<td>'.$e->getDateFin().'</td>
						<td>'.$e->getNombrePlace().'</td>
						<td>'.$n->avg_note.'</td>
						<td><a href="?module=participant&action=list&id_evenement='.$e->getIdEvenement().'">'._VOIR_.'</a></td>
						<td><a href="?module=note&action=addForm&id='.$e->getIdEvenement().'">'._NOTE_.'</a></td>
						<td><a href="?module=commentEvenement&action=list&id='.$e->getIdEvenement().'">'._VOIR_.' ('.CommentEvenement::getNbComment($e->getIdEvenement()).')</a></td>
						<td><a href="?module=equipe&action=list&id='.$e->getIdEvenement().'">'._VOIR_.'</a></td>
						<td><a href="?module=evenement&action=modifyForm&id='.$e->getIdEvenement().'">'._EDIT_.'</a></td>
						<td><a href="?module=evenement&action=delete&id='.$e->getIdEvenement().'">'._DELETE_.'</a></td>
					
					</tr>';
        }
        $html .= '</tbody></table>';
        echo $html;
        break;

    case "delete":
        $a = Evenement::getEvenement($_GET['id']);
        $a->delete();
        echo $a->getNom().' '._DELETED_;
        break;
}
?>
